package com.zzyl.serve.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.serve.domain.Reservation;
import com.zzyl.serve.service.IReservationService;
import com.zzyl.serve.vo.ReservationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约信息Controller
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags = "预约信息相关接口")
@Slf4j
public class MemberReservationController extends BaseController {

    @Autowired
    private IReservationService reservationService;


    /**
     * 查询当天取消预约数量
     *
     * @return
     */
    @GetMapping("/cancelled-count")
    @ApiOperation("查询当天取消预约数量")
    public R<Long> getCancelledReservationCount() {
        Long count = reservationService.getCancelledReservationCount();
        return R.ok(count);
    }

    /**
     * 查询每个时间段剩余预约次数
     *
     * @return
     */
    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public R<List<ReservationVo>> getReservationCountByTime() {
        List<ReservationVo> list = reservationService.getReservationCountByTime();
        return R.ok(list);
    }

    /**
     * 新增预约信息
     * @param reservation
     * @return
     */
    @PostMapping
    @ApiOperation("新增预约信息")
    public AjaxResult insertReservation(@RequestBody Reservation reservation) {
        return toAjax(reservationService.insertReservation(reservation));
    }

    /**
     * 查询预约信息列表
     * @param reservation
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("查询预约信息列表")
    public R<TableDataInfo> getReservationPage(Reservation reservation) {
        List<Reservation> list = reservationService.selectReservationList(reservation);
        return R.ok(getDataTable(list));
    }

    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public AjaxResult cancelReservation(@PathVariable Long id) {
        Reservation reservation = new Reservation();
        reservation.setId(id);
        reservation.setStatus(2);
        return toAjax(reservationService.updateReservation(reservation));
    }



}